<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>

<script type="text/javascript" src="<c:url value="/layout/javascript/paginator.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.form.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/form.js"/>">/**/</script>

<script type="text/javascript">
/* Contatore per l'upload dei file */
var filecount = 0;

var subCatErrOpts = {
    msg : "<bean:message key="subcat.load.msg" bundle="errors"/>",
	boxTitle : "<bean:message key="subcat.load.boxTitle" bundle="errors"/>",
	msgStatus: "<bean:message key="subcat.load.msgStatus" bundle="errors"/>"
};

var ticketFaqErrOpts = {
	msg : "<bean:message key="faq.load.msg" bundle="errors"/>",
    boxTitle : "<bean:message key="faq.load.boxTitle" bundle="errors"/>",
    msgStatus: "<bean:message key="faq.load.msgStatus" bundle="errors"/>"
};

$(document).ready(function() {
	var options = {
       target:        '#validationbox',
       iframe:        true,
       beforeSubmit:  function () {
							$('#validationbox').html('<img alt="<bean:message key="saving.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="saving.message"/>');
					        $('#validationbox').dialog('open');
					  },
	   //success: function() { $('#validationbox').dialog('close'); },
       error:         function () {
						  $('#validationbox').dialog('close');
                          showErrorDialog('#dialog', 
                                 { msg : "<bean:message key="ticket.save.msg" bundle="errors"/>",
                                   boxTitle : "<bean:message key="ticket.save.boxTitle" bundle="errors"/>",
                                   msgStatus: "<bean:message key="ticket.save.msgStatus" bundle="errors"/>" });
                      }
    };

    $('#formTicket').ajaxForm(options);
			
 	$("#subCategories").change(function () {
        $('#Searchresult').empty();
        $('#Searchresult').html('<img alt="<bean:message key="wait.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message" />');
        loadTicketFaqs('${pageContext.request.contextPath}/ticket/searchforfaqs.do');
    });

    $("#categories").change(function () {
        $('#Searchresult').empty();
        $('#Searchresult').html('<img alt="<bean:message key="wait.message" />" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message" />');
    	selectSubCategories($(this), '${pageContext.request.contextPath}/ticket/loadsubcategories.do', function(id) {
    		loadTicketFaqs('${pageContext.request.contextPath}/ticket/searchforfaqs.do');
        }, null);
        
    });
    
    selectSubCategories($('#categories'), '${pageContext.request.contextPath}/ticket/loadsubcategories.do', function(id) {
    	loadTicketFaqs('${pageContext.request.contextPath}/ticket/searchforfaqs.do');
    }, null);

    /* jQuery textarea resizer */
    $('textarea.resizable:not(.processed)').TextAreaResizer();

	$('#anotherfile').click(function (event) {
		event.preventDefault();
		anotherFiles();
	});
   
});
</script>

<div id="content">
		<!--FORM-->
		<fieldset id="fieldset">
			<legend class="fieldsetLabel"><bean:message key="ticket.new" bundle="ticket"/></legend>
			<div id="form_container">
				<html:form  styleId="formTicket" styleClass="appnitro" action="${requestScope.action}" enctype="multipart/form-data">
				    <html:hidden property="ticketID"/>
				    <html:hidden property="statusName"/>	    
					<ul>
						<li id="li_5Ticket" >
							<label class="description" for="categories"><bean:message key="ticket.category" bundle="ticket"/></label>
							<div>
								<html:select property="catID" styleClass="element select large" styleId="categories"> 
									<html:options collection="categories" property="categoryID" labelProperty="name"/>
								</html:select>
							</div>
						</li>		
						<li id="li_7Ticket" >
							<label class="description" for="subCategories"><bean:message key="ticket.subcategory" bundle="ticket"/></label>
							<div>
                                <select  class="element select large" id="subCategories" name="subCategoryID">
                                </select>							    
							</div> 
						</li>
						<li id="li_boxDevice" >
							<label class="description" for="deviceList">Device List </label>
							<div>
							    <html:select property="deviceID" styleClass="element select medium" styleId="deviceList">
							        <option selected="selected" value="">None</option> 
                                    <html:options collection="devices" property="deviceID" labelProperty="name"/>
                                </html:select>
							</div> 
						</li>		
						<li id="li_6Ticket" >
							<label class="description" for="priorities"><bean:message key="ticket.priority" bundle="ticket"/></label>
							<div>
								<html:select property="priorityName" styleClass="element select medium" styleId="priorities"> 
									<html:options collection="priorities" property="name" labelProperty="name" />
								</html:select>
							</div> 
						</li>
						<li id="li_9Ticket" >
                            <label class="description" for="assigned"><bean:message key="ticket.assignedto" bundle="ticket"/></label>
                            <div>
                                <html:select property="assignedId" styleClass="element select medium" styleId="assignedTo"> 
                                    <html:options collection="technics" property="userID" labelProperty="username"/>
                                </html:select>
                            </div> 
                        </li>       		
						<li id="li_1" >
							<label class="description" for="subject"><bean:message key="ticket.subject" bundle="ticket"/></label>
							<div>
								<html:text property="subject" styleId="subject" styleClass="element text medium" maxlength="255" /> 
							</div> 
						</li>		
						<li id="li_2Ticket" >
							<label class="description" for="detail"><bean:message key="ticket.detail" bundle="ticket"/></label>
							
							<html:textarea property="description" styleId="detail" styleClass="resizable element textarea small" /> 
							
						</li>		
						<li id="li_3Ticket" >
							<label class="description" for="mail"><bean:message key="ticket.mail" bundle="ticket"/></label>
							<div>
								<html:text property="email" styleId="mail" styleClass="element text medium" maxlength="255" /> 
							</div> 
						</li>		
						<li id="li_8" >
							<label class="description" for="checkMail"> </label>
							<span id="checkMail">
								<html:checkbox property="sendmail" value="true" styleId="sendmail" styleClass="element checkbox" />
								<label class="choice" for="sendmail"><bean:message key="ticket.enablesendmail" bundle="ticket"/></label>
							</span> 
						</li>		
						<li id="li_4Ticket" >
							<label class="description" for="attachement"><bean:message key="ticket.attachment" bundle="ticket"/></label>
							<div id="attachementdiv">
								<input type="file" name="attachmentFile[0]" id="attachement-0" value="" class="element file" />
							</div>
						</li>
						<li><a id="anotherfile" href="#"><bean:message key="ticket.attachment.add" bundle="ticket"/></a></li>
						<li class="buttons">
							<html:submit styleId="saveForm" styleClass="button_text" altKey="ticket.submitbutton">
							 <bean:message key="ticket.submitbutton" bundle="ticket"/>
							</html:submit>
						</li>
					</ul>
    			</html:form>	
			</div>
			
			<!--Assistenza alla compilazione della form-FAQs -->
			<div id="helpBox">
				<div id="hiddenresult" style="display:none;"></div>
			
				<div id="Pagination" class="pagination"></div>
		
				<br style="clear:both;" />
				<div id="Searchresult">
					<img alt="<bean:message key="wait.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message"/>
				</div>
			</div>
		</fieldset>	
</div>		
		